package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxLbYsy;
import cn.stylefeng.guns.modular.lx.mapper.LxLbYsyMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxLbYsyParam;
import cn.stylefeng.guns.modular.lx.model.result.LxLbYsyResult;
import  cn.stylefeng.guns.modular.lx.service.LxLbYsyService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 尹思莹
 * @since 2023-12-01
 */
@Service
public class LxLbYsyServiceImpl extends ServiceImpl<LxLbYsyMapper, LxLbYsy> implements LxLbYsyService {

    @Override
    public void add(LxLbYsyParam param){
        LxLbYsy entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxLbYsyParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxLbYsyParam param){
        LxLbYsy oldEntity = getOldEntity(param);
        LxLbYsy newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxLbYsyResult findBySpec(LxLbYsyParam param){
        return null;
    }

    @Override
    public List<LxLbYsyResult> findListBySpec(LxLbYsyParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxLbYsyParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxLbYsyParam param){
        return param.getLbId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxLbYsy getOldEntity(LxLbYsyParam param) {
        return this.getById(getKey(param));
    }

    private LxLbYsy getEntity(LxLbYsyParam param) {
        LxLbYsy entity = new LxLbYsy();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
